package com.devsoft.foodfrenzy;

import java.util.Date;


public class Timer {	//handles in-game events like power-ups
	
	private long duration;
	private long start_time;
	private boolean is_running;
	

	public Timer(long millisecs)
	{
		this.duration = millisecs;
		this.start_time = 0;
		this.is_running = false;
		
	}
	
	
	public void start()
	{
		this.start_time = new Date().getTime();
		this.is_running = true;
		
	}
	
	
	public long getCurrentTime()
	{
		return (new Date().getTime() - start_time);
		
	}
	

	public void printCountdown()
	{
		System.out.print((this.duration - this.getCurrentTime()) / 60000);		//Minutes
		System.out.print(":");
		System.out.print(((this.duration - this.getCurrentTime()) / 1000) % 60);	//Seconds
		System.out.print(":");
		System.out.print((this.duration - this.getCurrentTime()) % 1000);			//Milliseconds
		System.out.println();
		
	}
	

	public void printTime()
	{
		System.out.print(this.getCurrentTime() / 60000);				//Minutes
		System.out.print(":");
		System.out.print((this.getCurrentTime() / 1000) % 60);			//Seconds
		System.out.print(":");
		System.out.print(this.getCurrentTime() % 1000);					//Milliseconds
		System.out.println();
		
	}
	
	
	public String getCountdown()
	{
		return ((this.duration - this.getCurrentTime()) / 60000 + ":" +
			   ((this.duration - this.getCurrentTime()) / 1000) % 60 + ":" + 
			    (this.duration - this.getCurrentTime()) % 1000);
		
	}
	
	
	public void addTime(int more_time)
	{
		this.duration += more_time;
		
	}
	
	
	public boolean running()
	{
		if(this.getCurrentTime() >= duration)
			is_running = false;
		
		return is_running;
		
	}
	
	
}
